package com.example.webcomen.Utill;

import com.example.webcomen.Model.*;

import java.util.ArrayList;
import java.util.List;

public class ToInfo {
    public static List<UserInfo> toUserInfo(List<User> userList){
        List<UserInfo> userInfoList=new ArrayList<>();
        userList.forEach(user -> {
            userInfoList.add(new UserInfo(user.getUsername(), user.getId(),
                    user.getStatus(),user.getSign(),picToNoStatic(user.getAvatar())));
        });
        return userInfoList;
    }
    public static List<GroupInfo> toGroupInfo(List<Group> groupList){
        List<GroupInfo> groupInfos=new ArrayList<>();
        groupList.forEach(group -> {
            groupInfos.add(new GroupInfo(group.getGroupname(), group.getId(),
                    picToNoStatic(group.getAvatar())));
        });
        return groupInfos;
    }
    public static UserInfo toUserInfo(User user ){
        return   new UserInfo(user.getUsername(), user.getId(),
                    user.getStatus(),user.getSign(),picToNoStatic(user.getAvatar()));
    }
    public static GroupInfo toGroupInfo(Group group){
        return new GroupInfo(group.getGroupname(), group.getId(), picToNoStatic(group.getAvatar()));
    }
    public static FriendGroupInfo toFriendGroupInfo(FriendGroup group){
        return new FriendGroupInfo(group.getGroupname(),group.getId(),  new ArrayList<UserInfo>());
    }
    public static AddMessage toAddMessage(AddMessageInfo addMessageInfo){
        return new AddMessage(addMessageInfo.getFromUid(), addMessageInfo.getToUid(), addMessageInfo.getGroupId(),
                addMessageInfo.getRemark(),addMessageInfo.getType(), addMessageInfo.getTime());
    }
    public static AddMessageInfo toAddMessageInfo(AddMessage addMessage){
        return new AddMessageInfo(addMessage.getFromUid(), addMessage.getToUid(), addMessage.getGroupId(),
                addMessage.getType(), addMessage.getTime(),addMessage.getRemark());
    }
    public static List<AddMessageInfo> toAddMessageInfoList(List<AddMessage> list){
        ArrayList<AddMessageInfo> a=new ArrayList<>();
        list.forEach(addMessage -> {
            a.add(toAddMessageInfo(addMessage));
        });
        return a;
    }
    public static String picToNoStatic(String a){
        return a.substring(7);
    }

}
